<template>
    <div class="sidebar">
        <!-- <div v-for="(item,index) in items" :key="index" :class="chosecss==item.id? 'color':'nav'" @click="chose(item.id,item.url)" >
            <div :class="item.icon">       {{item.title}}</div>
        </div> -->


        <el-menu :default-active="onRoutes" class="el-menu-vertical-demo" 
            background-color="#184155" text-color="#fff" active-text-color="#20a0ff"  router>
            <template v-for="item in navlist" class="navtitle">
                <template v-if="item.nav">
                    <el-submenu :index="item.url" :key="item.id">
                        <!-- 一级标签 -->
                        <template slot="title">
                            <i :class="item.icon"></i>
                            <span slot="title">{{ item.title }}</span>
                        </template>

                        <template v-for="subItem in item.nav">
                            <el-menu-item :index="subItem.url" :key="subItem.url">
                            <i :class="subItem.icon"></i>
                            <span slot="title">{{ subItem.title }}</span>
                            </el-menu-item>
                        </template> 
                    </el-submenu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.url" :key="item.url">
                        <i :class="item.icon"></i>
                        <span slot="title">{{ item.title }}</span>
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script>
export default {
    data() {
        return {
            chosecss: 0,
            nav2:[],//管理员导航数据
            navlist: [{ id: 1, title: '系统首页', url: '/home', icon: 'el-icon-s-home' },
            ],//左侧导航数据
            items: [
            { id: 3, title: '日程安排', url: '/daily', icon: 'icon iconfont icon-richeng' },
            { id: 4, title: '工资信息', url: '/money', icon: 'icon iconfont icon-gongzitiao' },
            { id: 5, title: '请假信息', url: '/rest', icon: 'icon iconfont icon-qingjia1' },
            { id: 6, title: '办公用品', url: '/workthing', icon: 'icon iconfont icon-Pen-Holder' },
            { id: 7, title: '合同信息', url: '/hetong', icon: 'icon iconfont icon-hetong-1' },
            { id: 8, title: '消息管理', url: '/msg', icon: 'icon iconfont icon-xinxi' },
            { id: 9, title: '培训信息', url: '/study', icon: 'icon iconfont icon-peixunjihua' },
            { id: 10, title: '员工信息', url: '/worker', icon: 'icon iconfont icon-yuangong' }
            ]
        };
    },
    computed: {
        onRoutes() {
            return this.$route.path.replace('/', '');
        }
    },
    methods: {
        chose(id, url) {//点击侧边栏，跳转路由
            this.chosecss = id;
            this.$router.push(url)
        },
         handleOpen(key, keyPath) {
        console.log(key, keyPath);
      },
      handleClose(key, keyPath) {
        console.log(key, keyPath);
      }
    },
    created() {
        var that = this;
        var username = this.$route.query.username;
          if (this.$route.query.admin) {//管理员数据
            this.$axios.get(`http://127.0.0.1:9090/manigetnav?userGH=${username}`).then(function(res){
                that.navlist.push({id:2,title:'部门管理',icon:'el-icon-menu',url:'/table',nav:[]})
                that.navlist[1].nav=res.data.data
            })
          }else{
            that.navlist.push({id:2,title:'个人管理',icon:'el-icon-menu',url:'/table',nav:[]})
            that.navlist[1].nav=that.items
        }
    },
}
</script>

<style>
.sidebar {
    width: 100%;
    height: 100%;
    background: #254055;
}

.sidebar::-webkit-scrollbar {
    width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
    width: 250px;
}
.sidebar > ul {
    height: 100%;
}

.el-submenu .el-menu-item {
   height: 50px;
    line-height: 50px;
    padding: 0 45px;
    min-width: 200px;
    text-align: center;
}
.el-menu-item {
    height: 56px;
    line-height: 56px;
    font-size: 14px;
    color: #303133;
    padding: 0 52px;
    list-style: none;
    cursor: pointer;
    position: relative;
    transition: border-color .3s,background-color .3s,color .3s;
    box-sizing: border-box;
    white-space: nowrap;
}
.el-submenu__title {
    height: 56px;
    line-height: 56px;
    font-size: 14px;
    color: #303133;
    padding: 0 53px;
    list-style: none;
    cursor: pointer;
    position: relative;
    transition: border-color .3s,background-color .3s,color .3s;
    box-sizing: border-box;
    white-space: nowrap;
}
.sidebar .nav {
    color: #fff;
    text-align: center;
    width: 100%;
    height: 60px;
    line-height: 60px;
    font-size: 17px;

}

.sidebar i{
    margin-right: 5px;
}

</style>